package org.chen.controller;

import lombok.RequiredArgsConstructor;
import org.chen.domain.dto.VideoStatisticsDTO;
import org.chen.domain.vo.TaskVO;
import org.chen.service.VideoTaskService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1")
@RequiredArgsConstructor
public class VideoApiController {

    private final VideoTaskService videoTaskService;

    @GetMapping("/statistics")
    public VideoStatisticsDTO getStatistics() {
//        System.out.println("请求到达了: VideoApiController");
//        VideoStatisticsDTO statistics = videoTaskService.getStatistics();
//        System.out.println(statistics);
        return videoTaskService.getStatistics();
    }

    @GetMapping("/tasks/recent")
    public List<TaskVO> getRecentTasks(@RequestParam(defaultValue = "5") int limit) {
//        System.out.println("请求到达了: VideoApiController");
//        List<TaskVO> recentTasks = videoTaskService.getRecentTasks(limit);
//        System.out.println(recentTasks);
        return videoTaskService.getRecentTasks(limit);
    }

    @GetMapping("/tasks/trend")
    public Map<String, Integer> getTaskTrend(
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") LocalDateTime startTime,
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") LocalDateTime endTime) {
//        System.out.println("请求到达了: VideoApiController");
//        Map<String, Integer> taskTrend = videoTaskService.getTaskTrend(startTime, endTime);
//        System.out.println(taskTrend);
        return videoTaskService.getTaskTrend(startTime, endTime);
    }
}